<div id="tb<?php echo $uniqid;?>" style="padding:5px">
    <table cellspacing="0" cellpadding="0">
        <tbody>
        <tr>
            <td><a href="javascript:void(0);" onclick="companyauditView();" class="l-btn l-btn-small l-btn-plain"><span
                    class="l-btn-left l-btn-icon-left"><i class="iconfont icon-bianji"></i><span class="l-btn-text">查看</span></span></a></td>
            <td>
                <div class="datagrid-btn-separator"></div>
            </td>
            <td><a href="javascript:void(0);" onclick="companyauditReload();" class="l-btn l-btn-small l-btn-plain"><span
                    class="l-btn-left l-btn-icon-left"><i class="iconfont icon-shuaxin"></i><span class="l-btn-text">重载</span></span></a></td>
            <td>
                <div class="datagrid-btn-separator"></div>
            </td>
            <td>&nbsp;&nbsp;<input id="companyauditKeywords" placeholder="企业名称" style="width:100px" type="text" class="forminput inputstyle"> </input></td>
            <td><a href="javascript:void(0);" onclick="companyauditSearch();" class="l-btn l-btn-small l-btn-plain"><span
                    class="l-btn-left l-btn-icon-left"><i class="iconfont icon-sousuo"></i><span class="l-btn-text">查询</span></span></a></td>
        </tr>
        </tbody>
    </table>
</div>
<div class="con" onselectstart="return false;" style="-moz-user-select:none;">
    <table id="companyaudit"></table>
</div>
<div id="companyauditdlg" class="easyui-dialog" title="信息框" style="width: 860px; height: 710px;" closed="true"></div>

<script>
    var companyauditView = function (id) {
        if(!id && !$('#companyaudit').datagrid('getSelected')){
            $.messager.alert('提示', '请先选择要编辑的行！', 'warning');
            return false;
        }
        let company_id = id ? id : $('#companyaudit').datagrid('getSelected').company_id;
        if (company_id) {
            $("#companyauditdlg").dialog({
                title: '审核企业信息',
                closed: false,
                width: 860,
                height: 710,
                cache: false,
                href: '/admin/audit/companyView?id=' + company_id,
                modal: true,
                buttons: [{
                    text: '保存',
                    id: 'companyauditsubmit',
                    iconCls: 'icon-ok',
                }, {
                    text: '关闭',
                    iconCls: 'icon-no',
                    handler: function () {
                        $("#companyauditdlg").dialog('close');
                    }
                }]
            });
        } else {
            $.messager.alert('提示', '请先选择要编辑的行！', 'warning');
        }
    };
    var companyauditReload = function () {
        $("#companyaudit").datagrid('reload');
    };
    var companyauditSearch = function () {
        var height = $(window).height() - $(".top").height() - 46;//表格高度
        var width = $(window).width() - $(".leftmenu").width() - 13;//表格高度
        $("#companyaudit").datagrid({
            title: '企业认证',
            width: width,
            height: height,
            singleSelect: true,//如果为true，则只允许选择一行
            striped: true,//是否显示斑马线效果。
            rownumbers: true,//如果为true，则显示一个行号列。
            pagination: true,//是否显示分页
            pageSize: 20,
            pageList: [20, 25, 30, 35],
            method: 'post',
            sortName: 'created_at',
            sortOrder: 'desc',
            url: '/admin/audit/company',
            queryParams: {keywords: $('#companyauditKeywords').val()},
            fitColumns: true,//真正的自动展开/收缩列的大小，以适应网格的宽度，防止水平滚动。
            nowrap: true,//如果为true，则在同一行中显示数据。设置为true可以提高加载性能。 是否换行
            selectOnCheck: true,
            checkOnSelect: true,
            toolbar: '#tb<?php echo $uniqid;?>',
            rowStyler: function (index, row) {
                if (row.status == 0) {
                    return 'color:#dc324d;';
                }
            },
            columns: [[
                {field: 'full_name', title: '单位全称', width: fixWidth(15)},
                {field: 'licence', title: '注册证号/信用代码', width: fixWidth(15)},
                {
                    field: 'licence_img', title: '营业执照图片', width: fixWidth(10), formatter: function (value, rowData, rowIndex) {
                        return "<a class='example-image-link' data-lightbox='example-set' href='" + value + "'><img width='60' height='60' src='" + value + "'></a>";
                    }
                },
                {
                    field: 'audit_company', title: '审核结果', width: fixWidth(10), formatter: function (value, rowData, rowIndex) {
                        switch (parseInt(value)) {
                            case 0:
                                return '未提交';
                            case 1:
                                return '待审核';
                            case 2:
                                return '已通过';
                            case 3:
                                return '未通过';
                        }
                    }
                },
                {field: 'company_reason', title: '上次审核结果', width: fixWidth(15)},
                {
                    field: 'created_at', title: '注册时间', width: fixWidth(15), formatter: function (value, rowData, rowIndex) {
                        return rowData.subject.created_at;
                    }
                },
                {
                    field: 'action', title: '操作', width: fixWidth(30), formatter: function (value, rowData, rowIndex) {
                        if (value != '') {
                            return '<a href="javascript:;" class="l-btn l-btn-small" onclick="companyauditView(' + rowData.company_id + ')" ><span class="l-btn-left l-btn-icon-left"><span class="l-btn-text">查看</span><span class="l-btn-icon icon-search">&nbsp;</span></span></a>&nbsp;' +
                                '<a href="javascript:;" class="l-btn l-btn-small" onclick="companyauditApproved(' + rowData.company_id + ')" ><span class="l-btn-left l-btn-icon-left"><span class="l-btn-text">审核通过</span><span class="l-btn-icon icon-ok">&nbsp;</span></span></a>&nbsp;' +
                                '<a href="javascript:;" class="l-btn l-btn-small" onclick="companyauditFailed(' + rowData.company_id + ')" ><span class="l-btn-left l-btn-icon-left"><span class="l-btn-text">审核不通过</span><span class="l-btn-icon icon-no">&nbsp;</span></span></a>&nbsp;' +
                                '<a href="javascript:;" class="l-btn l-btn-small" onclick="companyauditDelete(' + rowData.company_id + ')" ><span class="l-btn-left l-btn-icon-left"><span class="l-btn-text">删除</span><span class="l-btn-icon icon-remove">&nbsp;</span></span></a>';
                        }
                    }
                },
            ]],
            onDblClickRow: function (index, field) {
                companyauditView();
            }
        });
    };
    var companyauditApproved = function (company_id) {
        $.messager.confirm('提示', '确定审核通过吗？', function (r) {
            if (r) {
                $.messager.progress();
                $.post('/admin/audit/companystatus', {id: company_id, status: 2}, function (data) {
                    $.messager.progress('close');
                    if (data.ret == 0) {
                        $.messager.show({
                            title: '提示',
                            msg: data.msg,
                            timeout: 3000,
                            showType: 'slide'
                        });
                        companyauditReload();
                    } else {
                        $.messager.alert('提示', data.msg, 'warning');
                    }
                }, 'json');
            }
        });
    };
    var companyauditFailed = function (company_id) {
        $.messager.prompt('提示', '请输入审核失败原因', function (r) {
            if (r) {
                $.messager.progress();
                $.post('/admin/audit/companystatus', {id: company_id, status: 3, reason: r}, function (data) {
                    $.messager.progress('close');
                    if (data.ret == 0) {
                        $.messager.show({
                            title: '提示',
                            msg: data.msg,
                            timeout: 3000,
                            showType: 'slide'
                        });
                        companyauditReload();
                    } else {
                        $.messager.alert('提示', data.msg, 'warning');
                    }
                }, 'json');
            }
        });
    };
    var companyauditDelete = function (company_id) {
        $.messager.confirm('提示', '确定删除记录吗？', function (r) {
            if (r) {
                $.messager.progress();
                $.post('/admin/audit/delete', {id: company_id}, function (data) {
                    $.messager.progress('close');
                    if (data.ret == 0) {
                        $.messager.show({
                            title: '提示',
                            msg: data.msg,
                            timeout: 3000,
                            showType: 'slide'
                        });
                        companyauditReload();
                    } else {
                        $.messager.alert('提示', data.msg, 'warning');
                    }
                }, 'json');
            }
        });
    };
    companyauditSearch();
</script>
